import axios from 'axios';

const api = axios.create({
  baseURL: 'http://localhost:4001',
  timeout: 5000,
});

export const login = (username, password) => {
  return api
    .get('/users', {
      params: {
        username,
        password,
      },
    })
    .then((response) => {
      const users = response.data;
      if (users.length === 1) {
        return Promise.resolve(users[0]);
      }
      return Promise.reject(new Error('用户名或密码错误'));
    });
};